package com.ionehe.group.common.io;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * Copyright (c) 2020 ionehe.com
 * Date: 2020/11/24
 * Time: 下午05:25
 *
 * @author 2020年 <a href="mailto:a@ionehe.com">秀</a>
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class Paging<T> implements Serializable{

    private static final long serialVersionUID = 7319625407191377939L;

    protected Long total;
    protected List<T> data;

    public Paging() {
    }

    public Paging(Long total, List<T> data) {
        this.total = total;
        this.data = data;
    }

    public static <T> Paging<T> empty(Class<T> clazz) {
        List<T> emptyList = Collections.emptyList();
        return new Paging(0L, emptyList);
    }

    public static <T> Paging<T> empty() {
        return new Paging(0L, Collections.emptyList());
    }

    public Boolean isEmpty() {
        return Objects.equals(0L, this.total) || this.data == null || this.data.isEmpty();
    }
}
